package 文件io;
import java.io.*;

public class 对象流
{
	public static void main(String[]args){
		writeObject();
		readeObject();
	}
	//对象输出流  对象的序列化 
	//把对象写入文件:实际上是写入对象的类名 属性名 属性值等
	private static void writeObject(){
		Student st=new Student("小明",18,"男");//多个对象，可以写入对象数组 传入对象输出流
		File file=new File(FilePath.PATH+"/test.obj");
		try
		{
			OutputStream out=new FileOutputStream(file);
			ObjectOutputStream oos=new ObjectOutputStream(out);
			oos.writeObject(st);
			oos.close();
		}
		catch (FileNotFoundException e){}
		catch(IOException e){}
	}
	//对象输入流  对象反序列化
	//从文件读取对象内容，还原成对象
	private static void readeObject(){
		File file=new File(FilePath.PATH+"/test.obj");
		try
		{
			InputStream in=new FileInputStream(file);
			ObjectInputStream ois=new ObjectInputStream(in);
			System.out.println(ois.readObject());
		}
		catch (FileNotFoundException e){}
		catch(IOException e){}
		catch (ClassNotFoundException e){}
	}
}
